package com.wlr.study.interview;

import java.util.concurrent.*;

/**
 * @author lrwang
 * @version 1.0
 * @date 2023/1/30 10:20
 */
public class VolatileTest {
    public static volatile int i = 1;

    public static void main(String[] args) throws ExecutionException, InterruptedException {
        new Thread(() -> {
            while (i == 1) {
            }
            System.out.println("监听到了i值的变化，i的值是"+ i);
        }).start();
        try {
            Thread.sleep(100);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("修改了i的值");
        i = 2;
        System.out.println(i);
    }
}
